package com.yellowpage.white.util;


public class StringUtils {

	/**
	 * 根据小写简拼字母或数字生成简拼码
	 * 
	 * @param number
	 * @return
	 */
	public static String getNumFromLetter(String number) {

		String num = "";
		for (int i = 0; i < number.length(); i++) {
			String c = number.charAt(i) + "";
			if (c.equals("1")) {
				num = num + "1";
				continue;
			} else if (c.equals("2") || c.equals("a") || c.equals("b")
					|| c.equals("c")) {
				num = num + "2";
				continue;
			} else if (c.equals("3") || c.equals("d") || c.equals("e")
					|| c.equals("f")) {
				num = num + "3";
				continue;
			} else if (c.equals("4") || c.equals("g") || c.equals("h")
					|| c.equals("i")) {
				num = num + "4";
				continue;
			} else if (c.equals("5") || c.equals("j") || c.equals("k")
					|| c.equals("l")) {
				num = num + "5";
				continue;
			} else if (c.equals("6") || c.equals("m") || c.equals("n")
					|| c.equals("o")) {
				num = num + "6";
				continue;
			} else if (c.equals("7") || c.equals("p") || c.equals("q")
					|| c.equals("r") || c.equals("s")) {
				num = num + "7";
				continue;
			} else if (c.equals("8") || c.equals("t") || c.equals("u")
					|| c.equals("v")) {
				num = num + "8";
				continue;
			} else if (c.equals("9") || c.equals("w") || c.equals("x")
					|| c.equals("y") || c.equals("z")) {
				num = num + "9";
				continue;
			} else if (c.equals("0")) {
				num = num + "0";
				continue;
			}
		}

		return num;
	}

	/**
	 * 
	 * @param name
	 *            名字
	 * @return 名字的简拼
	 */
	public static String getJianPinOfName(String name) {

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < name.length(); i++) {
			String pinYinl = PingYinUtil.getPingYin(name.substring(i, i + 1));
			System.out.println("全拼："+pinYinl);
			if (null==pinYinl|"".equals(pinYinl)) {
				continue;
			}
			String letter = pinYinl.substring(0, 1);
			sb.append(letter);
		}

		return sb.toString();
	}
}
